#ifndef __System_Object_Core_H__
#define __System_Object_Core_H__
//+ [delegates] http://www.newty.de/fpt/fpt.html

//+ ThunkC Keywords
#define object_getType(t) ((System_Type *)t);

///<summary>
/// Object
///</summary>
enum {
	_System_ObjectVIndex_Equals,
	_System_ObjectVIndex_GetHashCode,
	_System_ObjectVIndex_ToString,
	_System_ObjectVIndexNext
};
typedef void *(*System_ObjectVector)();
typedef struct rSystem_Object {
	private struct rSystem_Type *__type;
	private struct rSystem_Object *__parent;
	private struct rSystem_Object *__next;
	private void *__interfaces;
	private System_ObjectVector __vtable[_System_ObjectVIndexNext];
} System_Object;

///<summary>
/// class
///</summary>
#define class(T,Tbase,classInterfaces,body) \
	extern System_Type _##T##Type; \
	typedef struct __##T##_ { \
		private System_Type *__type; \
		private System_Object *__parent; \
		private System_Object *__next; \
		private void *__interfaces; \
		Tbase Tbase##; classInterfaces \
		body \
	} T;
#define classT(T,T2,Tbase,classInterfaces,body) \
	extern System_Type _##T##_##T2##Type; \
	typedef struct __##T##_##T2##_ { \
		private System_Type *__type; \
		private System_Object *__parent; \
		private System_Object *__next; \
		private void *__interfaces; \
		Tbase Tbase##; classInterfaces \
		body \
	} bindT(T,T2);
#define classV(T,Tbase,classInterfaces,vbody,body) \
	extern System_Type _##T##Type; \
	typedef struct __##T##_ { \
		private System_Type *__type; \
		private System_Object *__parent; \
		private System_Object *__next; \
		private void *__interfaces; \
		private System_ObjectVector __vtable[_##T##VIndexNext]; \
		Tbase Tbase##; classInterfaces \
		body \
	} T; \
	/* vtable function */ \
	vbody
#define classTV(T,T2,Tbase,classInterfaces,vbody,body) \
	extern System_Type _##T##_##T2##Type; \
	typedef struct __##T##_##T2##_ { \
		private System_Type *__type; \
		private System_Object *__parent; \
		private System_Object *__next; \
		private void *__interfaces; \
		private System_ObjectVector __vtable[_##T##_##T2##VIndexNext]; \
		Tbase Tbase##; classInterfaces \
		body \
	} bindT(T,T2); \
	/* vtable function */ \
	vbody

///<summary>
/// interface
///</summary>
#define interface(T,classInterfaces,vbody) \
	extern System_Type _##T##Type; \
	typedef struct { \
		private System_Type *__type; \
		private System_Object *__parent; \
		private System_Object *__next; \
		private System_ObjectVector __vtable[_##T##VIndexNext]; \
		classInterfaces \
	} T; \
	/* vtable function */ \
	vbody
#define interfaceT(T,T2,classInterfaces,vbody) \
	extern System_Type _##T##_##T2##Type; \
	typedef struct { \
		private System_Type *__type; \
		private System_Object *__parent; \
		private System_Object *__next; \
		private System_ObjectVector __vtable[_##T##_##T2##VIndexNext]; \
		classInterfaces \
	} bindT(T,T2); \
	/* vtable function */ \
	vbody

///<summary>
/// classInterface
///</summary>
#define classInterface(A) A A;
#define classInterface2(A,B) A A;B B;
#define classInterface3(A,B,C) A A;B B;C C;
#define classInterface4(A,B,C,D) A A;B B;C C;D D;

///<summary>
/// Declare_Ctor
///</summary>
#define Declare_Ctor(n,access,T,...) \
	__device__ T *space(T,ctor##n)(T *t,__VA_ARGS__);
#define Declare_CtorT(n,access,T,T2,...) \
	__device__ bindT(T,T2) *spaceT(T,T2,ctor##n)(bindT(T,T2) *t,__VA_ARGS__);
#define Declare_DefaultCtor(access,T) \
	__device__ T *space(T,ctor)(T *t);
#define Declare_DefaultCtorT(access,T,T2) \
	__device__ bindT(T,T2) *spaceT(T,T2,ctor)(bindT(T,T2) *t);

#endif /* __System_Object_Core_H__ */


